<template>
    <provider :locale="locale">
        <div id="app">
            <router-view></router-view>
            <el-dialog :visible.sync="isShowCustomePopup" :lock-scroll="true" :center="true" :show-close="false" custom-class="custome-popup" :close-on-press-escape="false" fullscreen lock-scrol append-to-body>
                <custome-layout @close="()=>{$store.commit('SET_CUSTOME_SHOW',false)}"></custome-layout>
            </el-dialog>
        </div>
    </provider>
</template>

<script>
    import customeLayout from '@/components/custome/layout.vue'
    import zhCN from 'ant-design-vue/lib/locale-provider/zh_CN';
    import provider from 'ant-design-vue/lib/config-provider';
    export default {
        components: {
            customeLayout,
            provider
        },
        data() {
            return {
                isShowCustomePopup: false,
                locale: zhCN,
            }
        },
        computed: {
            storeCustomeShow() {
                return this.$store.state.custome.show
            },
            timMsg() {
                return this.$store.state.tim.msg
            },
            token() {
                return this.$store.state.token
            }
        },
        created() {
            // if (!this.$store.state.tim.status && window.localStorage.getItem('timInfo')) {
            //     this.getIM();
            // }
            if(this.$store.state.token){
              this.getUserRoot()
            }
        },
        methods: {
            // 获取当前权限列表
            getUserRoot() {
                this.$http.post('/api/root/Rbac/getMineRole')
                    .then(res => {
                        // console.log(res, '权限列表');
                        if (res.code == 1) {
                            let root_router = JSON.stringify(res.data)
                            this.$store.commit("SET_ROOT_ROUTER", root_router);
                            // this.$router.push('/manaindex')
                            // this.$message.success('登录成功');
                            console.log('1');
                        }
                    })
            },
            // getIM() {
            //     this.$http.post("/api/root/kefu/getAccount").then(res => {
            //         if (res.code === 1) {
            //             window.localStorage.setItem('timInfo', {
            //                 userID: res.data.im_user,
            //                 userSig: res.data.sig
            //             })
            //             this.$tim.login(res.data.im_user, res.data.sig)
            //         } else {
            //             this.$message(res.msg);
            //         }
            //     })
            // },
            getMsgText(message) {
                if (message.type == "TIMImageElem") {
                    return '图片消息'
                }
                if (message.type == "TIMCustomElem") {
                    let msg_content = typeof message.payload.data == 'object' ? JSON.parse(message.payload.data) : message.payload.data;
                    if (!msg_content) {
                        return ""
                    }
                    let Desc = JSON.parse(message.payload.description);
                    if (!Desc) {
                        return ""
                    }
                    let format = Desc.format;
                    if (!format) return "";
                    if (format == 'string' || format == 'system') {
                        return msg_content || ""
                    }
                    if (format == 'answer') {
                        return "图文消息"
                    }
                    if (format == 'case') {
                        return "案例推荐"
                    }
                    if (format == 'goods') {
                        return "商品推荐"
                    }
                    if (format == 'picture') {
                        return "图片消息"
                    }
                    if (format == 'store') {
                        return "店铺推荐"
                    }
                    if (format == 'team') {
                        return "施工队推荐"
                    }
                    if (format == 'designer') {
                        return "设计师推荐"
                    }
                    return '系统消息'
                }
                return '系统消息'


            }
        },
        watch: {
            storeCustomeShow(newVal, oldVal) {
                this.isShowCustomePopup = newVal;
            },
            timMsg(newVal, oldVal) {
                // if(!this.isShowCustomePopup){
                // 	this.$message('收到客服消息');
                // }
                this.$notify({
                    title: `收到[${newVal.nick||'客服'}]消息`,
                    message: this.getMsgText(newVal),
                    position: 'top-right'
                });
            },
            token(newVal, oldVal) {
                if (newVal) {
                    this.getIM()
                }
            }
        }
    }
</script>

<style lang="less">
@import '@/assets/styles/Flex.less';
@import '@/assets/styles/global.less';
    * {
        margin: 0;
        padding: 0;
        box-sizing: border-box;
    }

    #app,
    html,
    body {
        height: 100%;
    }
    button{
        line-height: normal !important;
    }
    img{
        vertical-align: inherit !important;
    }
</style>